cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        target: cc.Node,
        sprite: cc.SpriteFrame,
        checkedSprite: cc.SpriteFrame,
        checked: false,
        groupId: -1,
    },

    // use this for initialization
    onLoad: function () {
        if (cc.vv == null) {
            return;
        }
        if (cc.vv.radiogroupmgr == null) {
            var RadioGroupMgr = require("RadioGroupMgr");
            cc.vv.radiogroupmgr = new RadioGroupMgr();
            cc.vv.radiogroupmgr.init();
        }
        cc.vv.radiogroupmgr.add(this);

        this.refresh();
    },

    refresh: function () {
        var targetSprite = this.target.getComponent(cc.Sprite);
        if (this.checked) {
            targetSprite.spriteFrame = this.checkedSprite;
        }
        else {
            targetSprite.spriteFrame = this.sprite;
        }
    },

    check: function (value) {
        this.checked = value;
        this.refresh();
    },

    onClicked: function (e) {
        var index = e.target.name[e.target.name.length - 1];
        var leixingnode = cc.find('Canvas/CreateRoom/leixingxuanze');
        var jushunode = cc.find('Canvas/CreateRoom/xuanzejushu');
        var jushu = [['8局(房豆x8)', '16局(房豆x16)'], ['10局(房豆x10)', '20局(房豆x20)'], ['12局(房豆x12)', '24局(房豆x24)']];
        if (leixingnode) {
            for (var i = 0; i < leixingnode.children.length; ++i) {
                if (i == index) {
                    jushunode.children[0].getChildByName('title').getComponent(cc.Label).string = jushu[index][0]
                    jushunode.children[1].getChildByName('title').getComponent(cc.Label).string = jushu[index][1]
                    break;
                }
            }
        }
        cc.vv.radiogroupmgr.check(this);
    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },

    onDestroy: function () {
        if (cc.vv && cc.vv.radiogroupmgr) {
            cc.vv.radiogroupmgr.del(this);
        }
    }
});
